﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace craigsPack
{
    public sealed class CraigsListQueryStringBuilder : QueryStringBuilder
    {
        internal static readonly CraigsListQueryStringBuilder ForSaleQueryStringBuilder = new CraigsListQueryStringBuilder();
        internal static readonly CraigsListQueryStringBuilder JobsQueryStringBuilder = new CraigsListQueryStringBuilder();
        internal static readonly CraigsListQueryStringBuilder GigsQueryStringBuilder = new CraigsListQueryStringBuilder();
        internal static readonly CraigsListQueryStringBuilder ServicesQueryStringBuilder = new CraigsListQueryStringBuilder();
        internal static readonly CraigsListQueryStringBuilder HousingQueryStringBuilder = new CraigsListQueryStringBuilder();
      
        static CraigsListQueryStringBuilder()
        {
            ForSaleQueryStringBuilder["areaID"] = "";
            ForSaleQueryStringBuilder["subAreaID"] = "";
            ForSaleQueryStringBuilder["srchType"] = "A";
            ForSaleQueryStringBuilder["minAsk"] = " ";
            ForSaleQueryStringBuilder["maxAsk"] = " ";
            ForSaleQueryStringBuilder["hasPic"] = "1";
            ForSaleQueryStringBuilder["s"] = "0";
           

            JobsQueryStringBuilder["s"] = "0";
            JobsQueryStringBuilder["areaID"] = "";
            JobsQueryStringBuilder["subAreaID"] = "";
            JobsQueryStringBuilder["srchType"] = "A";
            JobsQueryStringBuilder["addOne"] = "telecommuting";
            JobsQueryStringBuilder["addTwo"] = "contract";
            JobsQueryStringBuilder["addThree"] = "internship";
            JobsQueryStringBuilder["addFour"] = "part-time";
            JobsQueryStringBuilder["addFive"] = "non-profit";
            JobsQueryStringBuilder["hasPic"] = "1";
            

            GigsQueryStringBuilder["s"] = "0";
            GigsQueryStringBuilder["areaID"] = "";
            GigsQueryStringBuilder["subAreaID"] = "";
            GigsQueryStringBuilder["srchType"] = "A";
            GigsQueryStringBuilder["addThree"] = "forpay";
            GigsQueryStringBuilder["hasPic"] = "1";
           

            ServicesQueryStringBuilder["s"] = "0";
            ServicesQueryStringBuilder["areaID"] = "";
            ServicesQueryStringBuilder["subAreaID"] = "";
            ServicesQueryStringBuilder["srchtype"] = "A";
            ServicesQueryStringBuilder["hasPic"] = "1";
           

            HousingQueryStringBuilder["s"] = "0";
            HousingQueryStringBuilder["areaID"] = "";
            HousingQueryStringBuilder["subAreaID"] = "";
            HousingQueryStringBuilder["srchType"] = "A";
            HousingQueryStringBuilder["minAsk"] = "";
            HousingQueryStringBuilder["maxAsk"] = "";
            HousingQueryStringBuilder["hasPic"] = "1";
            HousingQueryStringBuilder["bedrooms"] = "";
            HousingQueryStringBuilder["addTwo"] = "purrr";
            HousingQueryStringBuilder["addThree"] = "wooof";
           
        }
        
        public const string PAGE = "s";
        public const string AREAID = "areaID";
        public const string SUBID = "subAreaID";
        public const string SEARCHTYPE = "srchType";
        public const string HASPIC = "hasPic";
        public const string TELE = "tele";
        public const string CONTRACT = "contract";
        public const string INTERN = "intern";
        public const string PARTTIME = "partTime";
        public const string NONPROFIT = "nonProf";
        public const string CATS = "allowCats";
        public const string DOGS = "allowDogs";
        public const string BED = "bedrooms";
        public const string MAXPRICE = "maxAsk";
        public const string MINPRICE = "minAsk";
        public const string ISPAY = "isPay";



        public CraigsListQueryStringBuilder()
            :base()
        {
         
        }
       
        public override object this[string variable]
        {
            get
            {
                return base[variable];
            }
            set
            {

                if (value is bool)
                {
                    if (variable == CraigsListQueryStringBuilder.SEARCHTYPE)
                        value = ((bool)value ? "A" : "T");
                    else if (variable == CraigsListQueryStringBuilder.HASPIC)
                        value = ((bool)value ? "1" : "0");
                    else if ((bool)value)
                    {
                        switch (variable)
                        {
                            case CraigsListQueryStringBuilder.TELE:
                                variable = "addOne";
                                value = "telecommuting";
                                break;
                            case CraigsListQueryStringBuilder.CONTRACT :
                                variable = "addTwo";
                                value = "contract";
                                break;
                            case CraigsListQueryStringBuilder.INTERN :
                                variable = "addThree";
                                value = "internship";
                                break;
                            case CraigsListQueryStringBuilder.PARTTIME:
                                variable = "addFour";
                                value = "part-time";
                                break;
                            case CraigsListQueryStringBuilder.NONPROFIT:
                                variable = "addFive";
                                value = "non-profit";
                                break;
                            case CraigsListQueryStringBuilder.CATS :
                                variable = "addTwo";
                                value = "purrr";
                                break;
                            case CraigsListQueryStringBuilder.DOGS :
                                variable = "addThree";
                                value = "wooof";
                                break;
                            case CraigsListQueryStringBuilder.ISPAY :
                                variable = "addThree";
                                value = "forpay";
                                break;
                            default:
                                break;
                        }

                    }
                }

                   base[variable] = value;
            }
        }
    }
}
